const log4js = require('koa-log4');
const path = require('path');

const date = new Date().toLocaleDateString();

log4js.configure({
    appenders: {
        assets: {
            type: 'file',
            category: 'assetsLogger',
            maxLogSize: 104800,
            // backups: 100, // 当文件内容超过文件存储空间时，备份文件的数量
            filename: path.join(__dirname, '../logs', `${date}`, 'assets.log'),
        },
        error: {
            type: 'file',         // 日志类型
            category: 'errLogger',    // 日志名称
            maxLogSize: 104800, // 文件最大存储空间
            // backups: 100,
            filename: path.join(__dirname, '../logs', `${date}`, 'error.log'), //日志输出位置，当目录文件或文件夹不存在时自动创建
        },
        application: {
            type: 'file',
            category: 'resLogger',
            maxLogSize: 104800,
            // backups: 100,
            filename: path.join(__dirname, '../logs', `${date}`, 'application.log'),
        },
        out: {
            type: 'console'
        }
    },
    categories: {
        error: { appenders: ['error'], level: 'error' },
        application: { appenders: ['application'], level: 'info' },
        assets: { appenders: ['assets'], level: 'info' },
        default: { appenders: ['out'], level: 'info' }
    }
})

let errorLogger = log4js.getLogger('error'); // logger.info()
let appLogger = log4js.getLogger('application'); // logger.info()
let assetsLogger = log4js.getLogger('assets'); // logger.info()

module.exports = {
    errorLogger,
    assetsLogger,
    appLogger
};